<template>
<view class="cart-container" v-if="cart.length !==0">
    <my-address></my-address>
    <!-- 头部区域 -->
  <view class="handerBox">
     <!-- 左侧图标 -->
    <uni-icons type="shop" class="shop" size="16"></uni-icons>
     <text class="cart">购物车</text>
   </view>
   <uni-swipe-action>
     <block v-for="val in cart" :key="val.goods_id">
        <!-- 基础用法 -->
      <uni-swipe-action-item :right-options="options" @click="deleteShop(val.goods_id)">
          <my-goods :val="val" :showRadio="true" :countShow="true" @radioChange="radioChangeHandler" @num-change="numberChangeHandler"></my-goods>
       </uni-swipe-action-item>
       </block>
      </uni-swipe-action>
    <my-settle></my-settle>
  </view>
  <!-- 购物车为空的时候 -->
  <view class="empty-cart" v-else>
   <image src="../../static/cart_empty@2x.png"  class="empty-img"></image>
   <text class="tip-text">空空如也~</text>
  </view>
</template>

<script>
  import mixins from "@/mixins/tabbar-badge.js"
  import {mapState,mapMutations} from "vuex"
  export default {
     mixins: [mixins],
     computed:{
       ...mapState('moduleCart',['cart'])
     },
    data() {
      return {
        options: [{
              text: '删除', // 显示的文本内容
              style: {
                backgroundColor: '#C00000' // 按钮的背景颜色
              }
            }]
      };
    },
    methods:{
      ...mapMutations('moduleCart',['updateGoodsState','updateGoodsCount','removeGoodsById']),
      // 更改 商品 radio 的勾选状态
    radioChangeHandler(e){
     this.updateGoodsState(e)
    },
    // 更改 商品的 数量
    numberChangeHandler(e){
     this.updateGoodsCount(e)
    },
  // 点击删除按钮 删除数据
  deleteShop(id){
    // console.log(id)
    this.removeGoodsById(id)
  }
  },
  }
</script>

<style lang="scss">
.handerBox{
  display: flex;
  align-items: center;
  height: 40px;
  border-bottom: 1px solid #efefef;
  .shop {
    margin-left: 5px;
  }
  .cart {
    font-size: 14px;
    margin-left: 5px;
  }
}
.cart-container {
  padding-bottom: 50px;
}


.empty-cart{
  display: flex;
  flex-direction: column;
  align-items: center;
   padding-top: 150px;
  .empty-img{
    width: 90px;
    height: 90px;
    margin-bottom: 10px;
    .tip-text {
        font-size: 12px;
        color: gray;
    }
  }
}
</style>
